package cytargetlinker.conversion.data;

import cytargetlinker.conversion.graph.Graph;
import cytargetlinker.conversion.graph.Graph.Node;

public class DrugNode implements INode {

	private String id;
	private String chemicalName;
	private String biologicalType = "drug";
	private String cas;
	
	private DrugNode(String drugbank) {
		this.id = drugbank;
	}
	
	public static DrugNode createDrugNode(String id, String name, String cas) {
		
		DrugNode node = new DrugNode(id);
		node.setCas(cas);
		node.setChemicalName(name);
		
		return node;
	}
	
	@Override
	public Node getNode(Graph graph) {
		Node node = graph.addNode(getId());
		node.appendAttribute("drugbank", getId());
		node.appendAttribute("identifiers", getIdentifiers());
		node.appendAttribute("label", getId());
		if(getChemicalName() != null && !getChemicalName().equals("")) {
			node.appendAttribute("chemicalName", getChemicalName());
		}
		node.appendAttribute("biologicalType", getBiologicalType());
		return node;
	}
	
	/**
	 * creates Cytoscape list attribute containing
	 * all identifiers representing this drug
	 */
	private String getIdentifiers() {
		String ids = "[";
		ids = ids + getId();
		
		if(getCas() != null && !getCas().equals("")) {
			ids = ids + "," + getCas();
		}
		
		ids = ids + "]";
		return ids;
	}

	public String getBiologicalType() {
		return biologicalType;
	}

	public void setBiologicalType(String biologicalType) {
		this.biologicalType = biologicalType;
	}

	public String getCas() {
		return cas;
	}

	public void setCas(String cas) {
		this.cas = cas;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public String getChemicalName() {
		return chemicalName;
	}

	public void setChemicalName(String chemicalName) {
		this.chemicalName = chemicalName;
	}
}
